﻿namespace Oddo.Concept.Crm.Host.Console
{
    using System.IdentityModel.Selectors;
    using System.ServiceModel;
    using System.Web.Http;
    using System.Web.Http.SelfHost;
    using Common.Communication.Security;

    class Program
    {
        static void Main(string[] args)
        {
            
            var config = new HttpSelfHostConfiguration("https://localhost:4443")
                {
                    IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly,
                    ClientCredentialType = HttpClientCredentialType.Basic,
                    UserNamePasswordValidator = UserNamePasswordValidator.CreateMembershipProviderValidator(new CustomMemberShipProvider()),
                };

            
            //config.MessageHandlers.Add(new CompressionHandler());

            var jsonf = config.Formatters.JsonFormatter;
            config.Formatters.Clear();
            config.Formatters.Add(jsonf);

            var host = new ConsoleHostBootstrapper
                {
                    HttpHostConfiguration = config,
                    HttpHostServer = new HttpSelfHostServer(config)
                };

            host.Initialize();
            host.HttpHostServer.OpenAsync().Wait();

            System.Console.WriteLine("Server is started");
            System.Console.ReadLine();

            host.HttpHostServer.CloseAsync().Wait();
            host.Dispose();
        }
    }
}
